package main

import (
	"os"

	"github.com/gin-gonic/gin"
	"github.com/kpango/glg"
	"gopkg.in/alecthomas/kingpin.v2"
)

var (
	BasePath = kingpin.Flag("path", "base path to place result data").Default(".").String()
	Port     = kingpin.Flag("port", "port to listen").Default("9099").Short('p').String()
	LogFile  = kingpin.Flag("log", "name of log file").Default("crmlog-store.log").Short('l').String()
	KUrl     = kingpin.Flag("kurl", "Kafka url (forma: 'ip:port')").Default("127.0.0.1:9092").String()
	KTopic   = kingpin.Flag("ktopic", "Kafka topic").Default("crmlog").String()
	ProPort     = kingpin.Flag("pport", "Prometheus port").Default("10111").String()
	AuthPath = kingpin.Flag("auth", "path to place password file").Default(".").String()
)

func main() {
	kingpin.Parse()
	c, err := NewController(*BasePath, *LogFile)
	if err != nil {
		glg.Errorf("storeService.main: Failed to new controller: %v", err)
		os.Exit(1)
	}
	defer c.Close()
	go c.ms.ListenPrometheus(":"+*ProPort)
	router := gin.Default()
	router.POST("/REST/HTableService", c.PostHandler)
	router.Run(":" + *Port)
}
